package com.apes.pi.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import java.util.List;

/**
 * 队列接收者
 *
 * @author wuq
 * @create 2019-10-19 10:11
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = QueueReceiver.CONST_TABLE_NAME)
public class QueueReceiver extends Model {
    public static final String CONST_TABLE_NAME = "pi_Queue_Receiver";

    @Id
    @Column(name = "id", nullable = false, length = 64)
    @Comment("队列接收者编码")
    private String id;

    @ManyToOne
    @JoinColumn(name = "queue_id", referencedColumnName = "id")
    @Comment("队列编码")
    private PiQueue queue;

    @ManyToOne
    @JoinColumn(name = "receiver_id", referencedColumnName = "id")
    @Comment("接收者编码")
    private Receiver receiver;

    // 前置拦截器
    @Transient
    private List<Pipe> beforePipes;

    // 后置拦截器
    @Transient
    private List<Pipe> afterPipes;

    @Transient
    public String topicName(){
        return String.format("%s", id);
    }
}
